package com.example.demo.common.enums;

import com.example.demo.common.exception.DemoException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.stream.Stream;

/**
 * @author ccubee
 * @since 20-7-18 13:08
 */
@Getter
@AllArgsConstructor
public enum  ResultEnum {
    //
    OK(0, "成功"),
    FAIL(1, "失败"),
    VALID_TOKEN(11, "token无效")

    ;


    private Integer code;

    private String msg;

    public static ResultEnum of(Integer code ){
        return Stream.of(values()).filter(result -> code.equals(result.getCode())).findAny()
                .orElseThrow(() -> new DemoException("错误"));
    }

}
